package com.lagou.模块四;

public class TicketPool {
    private int cnt = 1000;

    public synchronized void saleTicket(){
        notify();
        if (cnt > 0){
            System.out.println("线程" + Thread.currentThread().getName() + "正在出票,当前剩余票数为" + (cnt-1));
            cnt--;
        }else{
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public synchronized void reTicket(){
        notify();
        if (cnt<1000) {
            System.out.println("线程" + Thread.currentThread().getName() + "收到退票,当前票数为" + (cnt + 1));
            cnt++;
        }else{
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
